package com.sunxu.job;

import lombok.Getter;
import lombok.Setter;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.PersistJobDataAfterExecution;
import org.quartz.SchedulerException;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * @Author 孙许
 * @Date 2019/12/08 21:27
 * @Description
 */
@PersistJobDataAfterExecution
public class MyJob implements Job {

    @Setter@Getter
    private Integer count;

    @Override
    public void execute(JobExecutionContext context) {
        LocalTime localTime = LocalTime.now();
//        System.out.println(context.getNextFireTime());
//        System.out.println(context.getTrigger().getStartTime());
//        try {
//            System.out.println(context.getScheduler().getJobGroupNames().get(0));
//        } catch (SchedulerException e) {
//            e.printStackTrace();
//        }
//        System.out.println(name);

        System.out.println(Thread.currentThread().getName() + "开始执行！" + localTime.toString());
        count++;
        System.out.println(count);
        context.getJobDetail().getJobDataMap().put("count", count);
        LocalTime endTime = LocalTime.now();
        System.out.println(Thread.currentThread().getName() + "结束执行！" + endTime.toString());
    }
}
